package com.example.visit

import androidx.lifecycle.ViewModel
import com.example.base.http.ApiServer
import com.example.base.mvi.BaseViewModel
import com.example.base.mvi.RequestType
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class VisitViewModel @Inject constructor(val apiServer: ApiServer): BaseViewModel<VisitIntent>() {
    override fun handlerIntent(it: VisitIntent) {
        when(it){
            is VisitIntent.getVisits->{
                httpRequest(apiServer.getVisits())
            }
            is VisitIntent.getVisitByStatus->httpRequest(apiServer.getVisitByStatus(it.status))
            is VisitIntent.getVisitByName->httpRequest(apiServer.getVisitByName(it.name))
            is VisitIntent.getVisitByPurpose->httpRequest(apiServer.getVisitByPurpose(it.purpose))
            is VisitIntent.addVisit -> httpRequest(apiServer.addVisit(toBody(it.beanItem)))
            is VisitIntent.deleteVisit -> httpRequest(apiServer.deleteVisit(it.id), RequestType.DELETE)
            is VisitIntent.getVisitById->httpRequest(apiServer.getVisitById(it.id))
            is VisitIntent.approveVisit->httpRequest(apiServer.approveVisit(it.id),RequestType.UPDATE)
            is VisitIntent.rejectVisit->httpRequest(apiServer.rejectVisit(it.id),RequestType.UPDATE)
            else -> {}
        }
    }
}